﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using Newtonsoft.Json;

public partial class BkCalendar : Basic
{
    public string strList = "";
    public string strYear = "";
    public string strCYear = "";
    public string strMonth = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        strCYear = DateTime.Now.ToString("yyyy");
        if (Request["date"] != null)
            strCYear = OTO.ToDate(Request["date"] + "-1", DateTime.Now).ToString("yyyy");
        DateTime cdate = OTO.ToDate(Request["date"] + "-1", DateTime.Now);
        //DateTime cdate = OTO.ToDate("2010-12-22", DateTime.Now);
        strList = sb热门板块日历(cdate).ToString();

        strYear = sbYear().ToString();

        //
        strMonth = strM(cdate);


    }

    protected StringBuilder sbYear()
    {
        StringBuilder sb = new StringBuilder();
        sb.Append("<ul>");
        //for (DateTime n = DateTime.Now.AddYears(-3); n <= DateTime.Now; n = n.AddYears(1))
        //{
        //    sb.AppendFormat("<li>{0}</li>", n.ToString("yyyy"));
        //}

        for (DateTime n = DateTime.Now; n >= DateTime.Now.AddYears(-3); n = n.AddYears(-1))
        {
        sb.AppendFormat("<li>{0}</li>", n.ToString("yyyy"));
        }

        sb.Append("</ul>");
        return sb;
    }

    protected string strM(DateTime v)
    {
        StringBuilder sb = new StringBuilder();
        sb.Append("<ul>");
        for (int i = 1; i < 13; i++)
        {
            if (v.Month == i)
                sb.AppendFormat("<li style=\"background:url(images/rili/month_bg_on.png); color:#F00;\"><span>{0}</span>月</li>", i);
            else
                sb.AppendFormat("<li><span>{0}</span>月</li>", i);
        }
        sb.Append("</ul>");
        return sb.ToString();
    }

    protected StringBuilder sb热门板块日历(DateTime cdate)
    {
        StringBuilder sb = new StringBuilder();
        try
        {
            string url = jsonUrl + "comm/Calendar.ashx?date=" + cdate.ToString("yyyy-MM-dd");
            string str = Pub.LoadData(url);
            List<BkRiLi> obj = JsonConvert.DeserializeObject<List<BkRiLi>>(str);

            sb.AppendLine("<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"1\" bgcolor=\"#d0d2d3\">");
            sb.AppendLine("<tr bgcolor=\"#f2f2f2\" align=\"center\">");
            sb.AppendLine("<td width=\"13%\" height=\"32\">日期</td>");
            sb.AppendLine("<td width=\"20%\">热门板块名称</td>");
            sb.AppendLine("<td width=\"18%\">可关注股票</td>");
            sb.AppendLine("<td width=\"29%\">理由</td>");
            sb.AppendLine("<td width=\"20%\">事件</td>");
            sb.AppendLine("</tr>");
            foreach (var m in obj)
            {
                sb.AppendLine("<tr>");
                sb.AppendLine("<td align=\"center\" bgcolor=\"#FFFFFF\">");
                sb.AppendLine("<div class=\"rl_tu rl_tu_bg1\">");
                sb.AppendLine("<h3>" + Pub.DateGetWeek(m.module.ctime) + "</h3>");
                sb.AppendLine("<h2 class=\"red\">" + m.module.ctime.ToString("dd") + "</h2>");
                sb.AppendLine("<h4>" + Pub.DateGetMonth(m.module.ctime) + "</h4>");
                sb.AppendLine("</div></td>");
                sb.AppendLine("<td align=\"center\" valign=\"middle\" bgcolor=\"#FFFFFF\">");
                sb.AppendLine("<div class=\"rl_bk\">");
                sb.AppendLine("<ul bkcode=\"" + m.module.ModuleId + "\" bkul=\"ul\">");
                sb.AppendLine("<li class=\"h2\"><a href=\"" + quoteUrl + "bk" + m.module.ModuleId + ".shtml\" class=\"b\">" + m.module.hotModule + "</a></li>");
                sb.AppendLine("<li class=\"h3 red\" bkzs=\"zs\">-</li>");
                sb.AppendLine("<li bkzd=\"zd\">-</li>");
                sb.AppendLine("</ul>");
                sb.AppendLine("</div></td>");
                sb.AppendLine("<td align=\"center\" bgcolor=\"#FFFFFF\">");
                sb.AppendLine("<div class=\"rl_gp\">");
                sb.AppendLine("<ul>");
                foreach (var n in m.stocks)
                {
                    sb.AppendLine("<li><a href=\"" + quoteUrl + "gg" + n.stock + ".shtml\" class=\"b\">" + n.stockname + "（" + n.stock + "）</a></li>");
                }
                sb.AppendLine("</ul>");
                sb.AppendLine("</div></td>");
                sb.AppendLine("<td bgcolor=\"#FFFFFF\">");
                sb.AppendLine("<div class=\"rl_ly\">" + m.module.reason + "</div></td>");
                sb.AppendLine("<td bgcolor=\"#FFFFFF\">");
                sb.AppendLine("<div class=\"rl_sj\">");
                sb.AppendLine("<ul>");
                foreach (var n in m.events)
                {
                    sb.AppendLine("<li>·<a href=\"" + GetNewsUrl("04","0", n.NewsId) + "\" class=\"b\">" + n.Title + "</a></li>");
                }
                sb.AppendLine("</ul>");
                sb.AppendLine("</div></td>");
                sb.AppendLine("</tr>");
            }
            sb.AppendLine("</table>");

        }
        catch { }
        return sb;
    }

}